# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=openvas
pkgver=7.0.1
pkgrel=2
pkgdesc="Open Vulnerability Assessment Scanner"
url="https://openvas.org/"
arch="all"
license="GPL-2.0-only"
depends="redis nmap coreutils openssl util-linux"
install="$pkgname.post-install"
pkgusers="gvm"
checkdepends="cppcheck"
makedepends="cmake bison gvm-libs-dev glib-dev libgcrypt-dev
	doxygen xmltoman graphviz libpcap-dev gpgme-dev
	clang-dev libssh-dev libksba-dev net-snmp-dev"
subpackages="$pkgname-doc $pkgname-config"
source="$pkgname-$pkgver.tar.gz::https://github.com/greenbone/openvas/archive/v$pkgver.tar.gz
	greenbone-nvt-sync.cron
	execinfo-musl-fix.patch
	malloc-trim.patch
	openvas-sysctl.conf"

prepare() {
	default_prepare
	mkdir build
}

build() {
	cd $builddir/build
	cmake -DCMAKE_BUILD_TYPE=None \
		-DSBINDIR=/usr/bin \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DSYSCONFDIR=/etc \
		-DLOCALSTATEDIR=/var \
		-DOPENVAS_RUN_DIR=/var/run/ospd \
	..
	make
}

check() {
	cd $builddir/build
	make check
}

package() {
	cd $builddir/build
	make DESTDIR="$pkgdir" install
	chown $pkgusers "$pkgdir"/etc/openvas
	chown $pkgusers "$pkgdir"/var/log/gvm
	chown $pkgusers "$pkgdir"/var/lib/openvas/plugins
}

config() {
	pkgdesc="Configuration files and scripts for openvas"
	install -Dm744 "$srcdir"/greenbone-nvt-sync.cron \
		"$subpkgdir"/etc/periodic/daily/greenbone-nvt-sync
	install -Dm644 "$builddir"/config/redis-openvas.conf "$subpkgdir"/etc/redis-openvas.conf
	install -Dm644 "$srcdir"/openvas-sysctl.conf "$subpkgdir"/etc/sysctl.d/02-openvas.conf
}

sha512sums="201ea02b25bf247320437ae5c82bdc95db981cc6bd99fdece9403573434db122cdc8db7b82a08cba34b6d67d5794b2364f798847c79b421495666adc95a02571  openvas-7.0.1.tar.gz
da53e5c5e3ab70749249c2bf6c4fe0e0d17a2afb39d4519eb7fdf873c3fedf925183db050ab5395a3fe7f1ce79d95bf4f55c69611205d00dc519ce15418bd915  greenbone-nvt-sync.cron
ffb2b6798eec54f39727e71ddc8e709c06b4dc8be37f05a87676233be3f0dd6701bdea6f61367af56b9d4342ec5e80489830d611ebe85861d7dda625941e785b  execinfo-musl-fix.patch
ae4f35ba0705eb16e98765f370a3225bbca6de4bcffeff20cde1d6d1a3487036ff5f683d9e38f0df3308770656876e240fc75c62ba9e2bb1d2e4998ac80e6395  malloc-trim.patch
1b85a5511e73a79bc2c9e11e773fee4d641a2f55760eb8e3f4a41cc0d73007e2f6300832c35dd2408838eb42efef54ba6e238a0ed551e34d21becc2aef499991  openvas-sysctl.conf"
